#include "xmlwriter.hpp"
#include "xmlreader.hpp"

void XMLWriter::write(const QString &name, BibStyle *bs)
{
    QFile file(name);
    file.open(QIODevice::WriteOnly);
    QXmlStreamWriter xmlWriter(&file);

    xmlWriter.setAutoFormatting(true);
    xmlWriter.writeStartDocument();
    xmlWriter.writeComment("Biblioteka stylow w aplikacji XWiz");

    xmlWriter.writeStartElement("bibstyle");

    int lastID;
    QString pom;

    for(unsigned int i=0; i<bs->_styles.size(); ++i)
    {
        lastID=(bs->_styles[i]->_StyleID);
        pom.setNum(lastID);
        xmlWriter.writeStartElement("style");
        xmlWriter.writeAttribute("id",pom);
        xmlWriter.writeAttribute("lt", QString::fromStdString(bs->_styles[i]->_LineType));
        xmlWriter.writeAttribute("lc", QString::fromStdString(bs->_styles[i]->_LineColor));
        xmlWriter.writeAttribute("lw", QString::fromStdString(bs->_styles[i]->_LineWidth));
        xmlWriter.writeAttribute("pt", QString::fromStdString(bs->_styles[i]->_PointType));
        xmlWriter.writeAttribute("ps", QString::fromStdString(bs->_styles[i]->_PointSize));
        xmlWriter.writeAttribute("pi", QString::fromStdString(bs->_styles[i]->_PointInterval));
        xmlWriter.writeEndElement();
    }
    lastID = bs->_styles.size()+1;

    xmlWriter.writeEndElement();
    xmlWriter.writeEndDocument();

    file.close();
}
